import {reactive, ref} from "vue";
import http from "../http";
import doctor from "./doctor.js";
import answer from "./answer.js";
const patient = reactive({
    patient_info_list: [],
    patient_info: {
        name: "",
        sex: null,
        birthday: "",
        weight: null,
        allergy_history: null,
        allergy_history_content: "",
        illness_history: null,
        illness_history_content: "",
        liver_function: null,
        renal_function: null,
        pregnancy_status: null,
        user: null,
    },
    type: 1,
    patient_id: null,
    addFlag:false,
    editFlag: false,
    delFlag: false,
    answer_info: {},
    get_patients_info(token){
        return http.get(`/patient/patients/`,{
          headers: {
            Authorization: "Bearer " + token,
          }
        }).then(response=>{
            this.patient_info_list = response.data.data;
            console.log(response.data)
        })
    },
    add_patient(token){
        return http.post(`/patient/patients/`, this.patient_info, {
            headers: {
                Authorization: "Bearer " + token,
            }
        }).then(response=>{
            console.log(response.data)
            this.addFlag = true
        })
    },
    edit_patient(token){
        return http.put(`/patient/edit_patients/${this.patient_id}/`, this.patient_info, {
            headers: {
                Authorization: "Bearer " + token,
            }
        }).then(response=>{
            console.log(response.data)
            return true
        })
    },
    get_patient_info_by_id(){
        return http.get(`/patient/patients_info/${this.patient_id}/`).then(response=>{
            console.log(response.data)
            this.patient_info = response.data;
        })

    },
    del_patient(){
        return http.delete(`/patient/del_patient/${this.patient_id}/`).then(response=>{
            this.delFlag = true
        })
    },
    save_answer(token){
        this.answer_info.question = answer.question;
        this.answer_info.imageList = answer.imageList;
        this.answer_info.doctor = localStorage.getItem("doctor_id")
        this.answer_info.patients_id = this.patient_id;

        return http.post(`/patient/save_answer/`, this.answer_info, {
            headers: {
                Authorization: "Bearer " + token,
                'Content-Type': 'multipart/form-data'
            }
        }).then(response=>{
            console.log(response.data)
            this.addFlag = true
        })
    }

})

export default patient;